<?php

class PriorityMerchandiseItemsForm extends Zend_Form
{
    public function __construct($options=array())
    {
        parent::__construct($options);

        // set form name and POST
        $this->setName('cash_advance_items');
        $this->setMethod('post');
        $this->setEnctype('multipart/form-data');

        // create basic field decorators
        $basicDecorators = array(
            'ViewHelper',
            array('Errors', array('placement'=>'prepend')),
            array('Label', array('placement'=>'prepend')),
            array( array('outerDiv'=>'HtmlTag'), array('tag'=>'div', 'style'=>'margin-top:5px')),
        );

        $code1 = new Zend_Form_Element_Text( "code1", array('size'=>10, 'required'=>true) );
		$code1->setDecorators($basicDecorators);
        $desc1 = new Zend_Form_Element_Textarea( "desc1", array('cols'=>40, 'rows'=>2, 'required'=>false) );
		$desc1->setDecorators($basicDecorators);
        $rank1 = new Zend_Form_Element_Text( "rank1", array('size'=>3, 'required'=>true) );
        $pic1 = new Zend_Form_Element_Text( "pic1", array('size'=>30, 'required'=>true) );
		$pic1->setDecorators($basicDecorators);
        $this->addElements( array( $code1, $desc1, $rank1, $pic1 ) );
		$rank1->setDecorators($basicDecorators);
        
        $code2 = new Zend_Form_Element_Text( "code2", array('size'=>10, 'required'=>true) );
		$code2->setDecorators($basicDecorators);
        $desc2 = new Zend_Form_Element_Textarea( "desc2", array('cols'=>40, 'rows'=>2, 'required'=>false) );
		$desc2->setDecorators($basicDecorators);
        $rank2 = new Zend_Form_Element_Text( "rank2", array('size'=>3, 'required'=>true) );
		$rank2->setDecorators($basicDecorators);
        $pic2 = new Zend_Form_Element_Text( "pic2", array('size'=>30, 'required'=>true) );
		$pic2->setDecorators($basicDecorators);
        $this->addElements( array( $code2, $desc2, $rank2, $pic2 ) );
        
        $code3 = new Zend_Form_Element_Text( "code3", array('size'=>10, 'required'=>true) );
		$code3->setDecorators($basicDecorators);
        $desc3 = new Zend_Form_Element_Textarea( "desc3", array('cols'=>40, 'rows'=>2, 'required'=>true) );
		$desc3->setDecorators($basicDecorators);
        $rank3 = new Zend_Form_Element_Text( "rank3", array('size'=>3, 'required'=>true) );
		$rank3->setDecorators($basicDecorators);
        $pic3 = new Zend_Form_Element_Text( "pic3", array('size'=>30, 'required'=>true) );
		$pic3->setDecorators($basicDecorators);
        $this->addElements( array( $code3, $desc3, $rank3, $pic3 ) );
        
        $code4 = new Zend_Form_Element_Text( "code4", array('size'=>10, 'required'=>true) );
		$code4->setDecorators($basicDecorators);
        $desc4 = new Zend_Form_Element_Textarea( "desc4", array('cols'=>40, 'rows'=>2, 'required'=>true) );
		$desc4->setDecorators($basicDecorators);
        $rank4 = new Zend_Form_Element_Text( "rank4", array('size'=>3, 'required'=>true) );
		$rank4->setDecorators($basicDecorators);
        $pic4 = new Zend_Form_Element_Text( "pic4", array('size'=>30, 'required'=>true) );
		$pic4->setDecorators($basicDecorators);
        $this->addElements( array( $code4, $desc4, $rank4, $pic4 ) );
        
        $code5 = new Zend_Form_Element_Text( "code5", array('size'=>10, 'required'=>true) );
		$code5->setDecorators($basicDecorators);
        $desc5 = new Zend_Form_Element_Textarea( "desc5", array('cols'=>40, 'rows'=>2, 'required'=>false) );
		$desc5->setDecorators($basicDecorators);
        $rank5 = new Zend_Form_Element_Text( "rank5", array('size'=>3, 'required'=>true) );
		$rank5->setDecorators($basicDecorators);
        $pic5 = new Zend_Form_Element_Text( "pic5", array('size'=>30, 'required'=>true) );
		$pic5->setDecorators($basicDecorators);
        $this->addElements( array( $code5, $desc5, $rank5, $pic5 ) );
        
        $code6 = new Zend_Form_Element_Text( "code6", array('size'=>10, 'required'=>true) );
		$code6->setDecorators($basicDecorators);
        $desc6 = new Zend_Form_Element_Textarea( "desc6", array('cols'=>40, 'rows'=>2, 'required'=>false) );
		$desc6->setDecorators($basicDecorators);
        $rank6 = new Zend_Form_Element_Text( "rank6", array('size'=>3, 'required'=>true) );
		$rank6->setDecorators($basicDecorators);
        $pic6 = new Zend_Form_Element_Text( "pic6", array('size'=>30, 'required'=>true) );
		$pic6->setDecorators($basicDecorators);
        $this->addElements( array( $code6, $desc6, $rank6, $pic6 ) );
        
        $code7 = new Zend_Form_Element_Text( "code7", array('size'=>10, 'required'=>true) );
		$code7->setDecorators($basicDecorators);
        $desc7 = new Zend_Form_Element_Textarea( "desc7", array('cols'=>40, 'rows'=>2, 'required'=>false) );
		$desc7->setDecorators($basicDecorators);
        $rank7 = new Zend_Form_Element_Text( "rank7", array('size'=>3, 'required'=>true) );
		$rank7->setDecorators($basicDecorators);
        $pic7 = new Zend_Form_Element_Text( "pic7", array('size'=>30, 'required'=>true) );
		$pic7->setDecorators($basicDecorators);
        $this->addElements( array( $code7, $desc7, $rank7, $pic7 ) );
        
        $code8 = new Zend_Form_Element_Text( "code8", array('size'=>10, 'required'=>true) );
		$code8->setDecorators($basicDecorators);
        $desc8 = new Zend_Form_Element_Textarea( "desc8", array('cols'=>40, 'rows'=>2, 'required'=>false) );
		$desc8->setDecorators($basicDecorators);
        $rank8 = new Zend_Form_Element_Text( "rank8", array('size'=>3, 'required'=>true) );
		$rank8->setDecorators($basicDecorators);
        $pic8 = new Zend_Form_Element_Text( "pic8", array('size'=>30, 'required'=>true) );
		$pic8->setDecorators($basicDecorators);
        $this->addElements( array( $code8, $desc8, $rank8, $pic8 ) );
        
        $code9 = new Zend_Form_Element_Text( "code9", array('size'=>10, 'required'=>true) );
		$code9->setDecorators($basicDecorators);
        $desc9 = new Zend_Form_Element_Textarea( "desc9", array('cols'=>40, 'rows'=>2, 'required'=>false) );
		$desc9->setDecorators($basicDecorators);
        $rank9 = new Zend_Form_Element_Text( "rank9", array('size'=>3, 'required'=>true) );
		$rank9->setDecorators($basicDecorators);
        $pic9 = new Zend_Form_Element_Text( "pic9", array('size'=>30, 'required'=>true) );
		$pic9->setDecorators($basicDecorators);
        $this->addElements( array( $code9, $desc9, $rank9, $pic9 ) );
        
        $code10 = new Zend_Form_Element_Text( "code10", array('size'=>10, 'required'=>true) );
		$code10->setDecorators($basicDecorators);
        $desc10 = new Zend_Form_Element_Textarea( "desc10", array('cols'=>40, 'rows'=>2, 'required'=>false) );
		$desc10->setDecorators($basicDecorators);
        $rank10 = new Zend_Form_Element_Text( "rank10", array('size'=>3, 'required'=>true) );
		$rank10->setDecorators($basicDecorators);
        $pic10 = new Zend_Form_Element_Text( "pic10", array('size'=>30, 'required'=>true) );
		$pic10->setDecorators($basicDecorators);
        $this->addElements( array( $code10, $desc10, $rank10, $pic10 ) );

        // form's submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Submit');

        $this->addElements(array($submit));

    }

    // dirt-simple template engine.
    public function render_with_template( $template_name )
    {
        $template_file_path = APP_DIR."/views/templates/$template_name";
        $template_contents = file_get_contents( $template_file_path );

        // str_replace() keywords, adding errors where needed
        $form_elements = $this->getElements();

		$template_contents = str_replace( "{ACTION}", $this->getAction(), $template_contents );
		
        $template_contents = str_replace( "{PM_CODE1}", $form_elements['code1'], $template_contents );
        $template_contents = str_replace( "{PM_DESC1}", $form_elements['desc1'], $template_contents );
        $template_contents = str_replace( "{PM_PIC1}", $form_elements['pic1'], $template_contents );
        $template_contents = str_replace( "{PM_RANK1}", $form_elements['rank1'], $template_contents );
        $template_contents = str_replace( "{PM_CODE2}", $form_elements['code2'], $template_contents );
        $template_contents = str_replace( "{PM_DESC2}", $form_elements['desc2'], $template_contents );
        $template_contents = str_replace( "{PM_PIC2}", $form_elements['pic2'], $template_contents );
        $template_contents = str_replace( "{PM_RANK2}", $form_elements['rank2'], $template_contents );
        $template_contents = str_replace( "{PM_CODE3}", $form_elements['code3'], $template_contents );
        $template_contents = str_replace( "{PM_DESC3}", $form_elements['desc3'], $template_contents );
        $template_contents = str_replace( "{PM_PIC3}", $form_elements['pic3'], $template_contents );
        $template_contents = str_replace( "{PM_RANK3}", $form_elements['rank3'], $template_contents );
        $template_contents = str_replace( "{PM_CODE4}", $form_elements['code4'], $template_contents );
        $template_contents = str_replace( "{PM_DESC4}", $form_elements['desc4'], $template_contents );
        $template_contents = str_replace( "{PM_PIC4}", $form_elements['pic4'], $template_contents );
        $template_contents = str_replace( "{PM_RANK4}", $form_elements['rank4'], $template_contents );
        $template_contents = str_replace( "{PM_CODE5}", $form_elements['code5'], $template_contents );
        $template_contents = str_replace( "{PM_DESC5}", $form_elements['desc5'], $template_contents );
        $template_contents = str_replace( "{PM_PIC5}", $form_elements['pic5'], $template_contents );
        $template_contents = str_replace( "{PM_RANK5}", $form_elements['rank5'], $template_contents );
        $template_contents = str_replace( "{PM_CODE6}", $form_elements['code6'], $template_contents );
        $template_contents = str_replace( "{PM_DESC6}", $form_elements['desc6'], $template_contents );
        $template_contents = str_replace( "{PM_PIC6}", $form_elements['pic6'], $template_contents );
        $template_contents = str_replace( "{PM_RANK6}", $form_elements['rank6'], $template_contents );
        $template_contents = str_replace( "{PM_CODE7}", $form_elements['code7'], $template_contents );
        $template_contents = str_replace( "{PM_DESC7}", $form_elements['desc7'], $template_contents );
        $template_contents = str_replace( "{PM_PIC7}", $form_elements['pic7'], $template_contents );
        $template_contents = str_replace( "{PM_RANK7}", $form_elements['rank7'], $template_contents );
        $template_contents = str_replace( "{PM_CODE8}", $form_elements['code8'], $template_contents );
        $template_contents = str_replace( "{PM_DESC8}", $form_elements['desc8'], $template_contents );
        $template_contents = str_replace( "{PM_PIC8}", $form_elements['pic8'], $template_contents );
        $template_contents = str_replace( "{PM_RANK8}", $form_elements['rank8'], $template_contents );
        $template_contents = str_replace( "{PM_CODE9}", $form_elements['code9'], $template_contents );
        $template_contents = str_replace( "{PM_DESC9}", $form_elements['desc9'], $template_contents );
        $template_contents = str_replace( "{PM_PIC9}", $form_elements['pic9'], $template_contents );
        $template_contents = str_replace( "{PM_RANK9}", $form_elements['rank9'], $template_contents );
        $template_contents = str_replace( "{PM_CODE10}", $form_elements['code10'], $template_contents );
        $template_contents = str_replace( "{PM_DESC10}", $form_elements['desc10'], $template_contents );
        $template_contents = str_replace( "{PM_PIC10}", $form_elements['pic10'], $template_contents );
        $template_contents = str_replace( "{PM_RANK10}", $form_elements['rank10'], $template_contents );
		
        $template_contents = str_replace( "{SUBMIT_BUTTON}", $this->submit, $template_contents );

        echo $template_contents;
    }
}

?>
